from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.
class UserProFile(AbstractUser):
    image = models.ImageField('用户头像', upload_to='user/', max_length=200, null=True, blank=True)
    nick_name = models.CharField('用户昵称', max_length=20, null=True, blank=True)
    birthday = models.DateField('用户生日', null=True, blank=True)
    gender = models.CharField('用户性别', choices=(('girl', '女'), ('boy', '男')), max_length=10, default='girl')
    address = models.CharField('用户地址', max_length=200, null=True, blank=True)
    phone = models.CharField('用户手机', max_length=11, null=True, blank=True)
    # 控制激活
    is_start = models.BooleanField('是否激活', default=False)

    def __str__(self):
        return self.username

    # 缓存原因,导致功能有问题
    def get_msg_cnt(self):
        from operations.models import UserMessage
        cnt = UserMessage.objects.filter(id=self.id, message_status=False).count()
        return cnt

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name


class BannerInfo(models.Model):
    image = models.ImageField('轮播图片', upload_to='banner', max_length=200)
    url = models.URLField('图片链接', max_length=200, default='http://www.atguigu.com')
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    def __str__(self):
        return str(self.image)

    class Meta:
        verbose_name = '轮播图信息'
        verbose_name_plural = verbose_name


class EmailVerifyCode(models.Model):
    code = models.CharField('邮箱验证码', max_length=20)
    email = models.EmailField('验证码邮箱', max_length=200)
    send_type = models.IntegerField('验证码类型', choices=((1, 'register'), (2, 'forget'), (3, 'change')))
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    def __str__(self):
        return self.code

    class Meta:
        verbose_name = '邮箱验证码信息'
        verbose_name_plural = verbose_name
